package com.hq.door.dto.demo;

import java.util.Iterator;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hq.door.pojo.UserInfor;

public class UserDTOGenerator extends AbstractDTOGenerator {

	@Override
	public Object generateDTO(Object bean, Selectors selector) {
		UserInfor ui = (UserInfor)bean;
		Iterator it = selector.iterator();
		selector.add(ui.getName());
		selector.add(ui.getCode());
		selector.add(ui.getAge()+"");
		selector.add(ui.getAddress());
		return selector;
	}

	@Override
	public Object generateDTO(Object bean) {
		return bean;
	}
	
	public static void main(String[] args) {
		
		Selectors selector = new Selectors();
		selector.add("name");
		selector.add("code");
		selector.add("age");
		selector.add("address");
		UserInfor user = new UserInfor("范海茹", "001", 23, "河北省冀州市南午村镇樊庄");
		UserDTOGenerator dto = new UserDTOGenerator();
		Object bean = dto.generateDTO(user,selector);
		ObjectMapper mapper = new ObjectMapper();
		String json = "";
		try {
			json = mapper.writeValueAsString(bean);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		System.out.println(json);
		
		/*
		UserInfor user = new UserInfor("范海茹", "001", 23, "河北省冀州市南午村镇樊庄");
		UserDTO dto = new UserDTO();
		Object bean = dto.generateDTO(user);
		ObjectMapper mapper = new ObjectMapper();
		String json = "";
		try {
			json = mapper.writeValueAsString(bean);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		System.out.println(json);
		*/
		
	}

}
